package labox.innovation.netcore;

/**
 * 接收的来自客户端的数据包
 * 
 */
public abstract class ReceivablePacket<T extends MMOClient<?>> extends AbstractPacket<T> implements Runnable {

	protected ReceivablePacket() {
	}

	protected abstract boolean read();

	public abstract void run();

	protected final void readByte(byte[] dst) {
		_buf.get(dst);
	}

	protected final void readByte(byte[] dst, int offset, int len) {
		_buf.get(dst, offset, len);
	}

	protected final byte readByte() {
		return _buf.get();
	}

	protected final int readUnByte() {
		return _buf.get() & 0xFF;
	}

	protected final int readUnShort() {
		return _buf.getShort() & 0xFFFF;
	}

	protected final short readShort() {
		return _buf.getShort();
	}

	protected final int readInt() {
		return _buf.getInt();
	}

	protected final long readLong() {
		return _buf.getLong();
	}

	protected final double readDouble() {
		return _buf.getDouble();
	}

	protected final float readFloat() {
		return _buf.getFloat();
	}

	protected final String readString() {
		int len = readUnShort();
		byte[] strBytes = new byte[len];
		for (int i = 0; i < strBytes.length; i++) {
			strBytes[i] = readByte();
		}
		return new String(strBytes,encoding);
	}
}
